import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { sApi } from '#/api/drone/drones';

import {DICT_TYPE, getDictOptions, getRangePickerDefaultProps} from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'sn',
      label: '序列号',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入序列号',
      },
    },
    {
      fieldName: 'droneModel',
      label: '无人机型号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入无人机型号',
      },
    },
    {
      fieldName: 'droneEnt',
      label: '无人机厂商',
      component: 'Input',
      componentProps: {
        placeholder: '请输入无人机厂商',
      },
    },
    {
      fieldName: 'description',
      label: '描述',
      component: 'Input',
    },
    {
      fieldName: 'status',
      label: '状态',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
        placeholder: '请选择状态',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'sn',
      label: '序列号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入序列号',
      },
    },
    {
      fieldName: 'droneModel',
      label: '无人机型号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入无人机型号',
      },
    },
    {
      fieldName: 'droneEnt',
      label: '无人机厂商',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入无人机厂商',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<sApi.s>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    // {
    //   field: 'id',
    //   title: '编号',
    //   minWidth: 120,
    // },
    {
      field: 'sn',
      title: '序列号',
      minWidth: 120,
    },
    {
      field: 'droneModel',
      title: '无人机型号',
      minWidth: 120,
    },
    {
      field: 'droneEnt',
      title: '无人机厂商',
      minWidth: 120,
    },
    {
      field: 'description',
      title: '描述',
      minWidth: 120,
    },
    {
      field: 'userName',
      title: '所属用户',
      minWidth: 120,
    },
    {
      field: 'deptName',
      title: '所属部门',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

// ==================== 子表（部门） ====================

/** 新增/修改的表单 */
export function useDeptFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: '部门名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入部门名称',
      },
    },
    {
      fieldName: 'parentId',
      label: '父部门id',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入父部门id',
      },
    },
    {
      fieldName: 'sort',
      label: '显示顺序',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入显示顺序',
      },
    },
    {
      fieldName: 'leaderUserId',
      label: '负责人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入负责人',
      },
    },
    {
      fieldName: 'phone',
      label: '联系电话',
      component: 'Input',
      componentProps: {
        placeholder: '请输入联系电话',
      },
    },
    {
      fieldName: 'email',
      label: '邮箱',
      component: 'Input',
      componentProps: {
        placeholder: '请输入邮箱',
      },
    },
    {
      fieldName: 'status',
      label: '部门状态（0正常 1停用）',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: [],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
  ];
}

// ==================== 子表（用户信息） ====================

/** 新增/修改的表单 */
export function useUsersFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'username',
      label: '用户账号',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户账号',
      },
    },
    {
      fieldName: 'password',
      label: '密码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入密码',
      },
    },
    {
      fieldName: 'nickname',
      label: '用户昵称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户昵称',
      },
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入备注',
      },
    },
    {
      fieldName: 'deptId',
      label: '部门ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入部门ID',
      },
    },
    {
      fieldName: 'postIds',
      label: '岗位编号数组',
      component: 'Input',
      componentProps: {
        placeholder: '请输入岗位编号数组',
      },
    },
    {
      fieldName: 'email',
      label: '用户邮箱',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户邮箱',
      },
    },
    {
      fieldName: 'mobile',
      label: '手机号码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入手机号码',
      },
    },
    {
      fieldName: 'sex',
      label: '用户性别',
      component: 'RadioGroup',
      componentProps: {
        options: [],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'avatar',
      label: '头像地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入头像地址',
      },
    },
    {
      fieldName: 'status',
      label: '帐号状态（0正常 1停用）',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: [],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'loginIp',
      label: '最后登录IP',
      component: 'Input',
      componentProps: {
        placeholder: '请输入最后登录IP',
      },
    },
    {
      fieldName: 'loginDate',
      label: '最后登录时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
  ];
}
